//菜单切换
$('#pro li').click(function () {
    $(this).addClass("greensy").siblings().removeClass("greensy");
    $('#tagpic>li').eq($(this).index()).addClass("greensy").siblings().removeClass("greensy");
});
//状态值
for (var i = 0; i < 10; i++) {
    var tab = $('#bttable tr td.statesy').eq(i).attr("ptstate");
    switch (tab) {
        case "1":
            $('#bttable tr td.statesy').eq(i).css('color', '#1e9fff');
            break;
        case "2":
            $('#bttable tr td.statesy').eq(i).css('color', '#242424');
            break;
        case "3":
            $('#bttable tr td.statesy').eq(i).css('color', '#ff0000');
            break;
    }
}
var login = new Validated();
login.rules = {
    "name": {
        "data": /^\S{1,}$/,
        "complete": "ok",
        "error": "不可以输入空格",
        "required": "true"
    }
    , "brandnames": {
        "data": /^\S{1,}$/,
        "complete": "ok",
        "error": "不可以输入空格",
        "required": "true"
    }, "ptmodel": {
        "data": /^\S{1,}$/,
        "complete": "ok",
        "error": "不可以输入空格",
        "required": "true"
    }, "manufacturers": {
        "data": /^\S{1,}$/,
        "complete": "ok",
        "error": "不可以输入空格",
        "required": "true"
    }, "parameters": {
        "data": /^\S{1,}$/,
        "complete": "ok",
        "error": "不可以输入空格",
        "required": "true"
    }
};
login.blur().focus();
$('button').click(function () {
    if (login.complete("name", "brandnames", "ptmodel", "manufacturers", "parameters")) {
        new Ajax("/my/product_net.jsp").keyvalue($('#product').serializeArray()).getJson(function (json) {
            if (json === 1) {
                $(window.parent.document).find('body').css({
                    "overflow-x": "hidden",
                    "overflow-y": "hidden"
                });
                $(window.parent.document).find("#vague").show();
                window.location.reload();
                $('input').val("");
            };
        })
    }
});
function state(txt) {
    switch (txt) {
        case "1":
            txt = "审核中";
            break;
        case "2":
            txt = "已通过";
            break;
        case "3":
            txt = "未通过";
            break;
    }
    return txt;
};
function col(txt, color) {
    switch (txt) {
        case "审核中":
            color = "#518ce1";
            break;
        case "未通过":
            color = "red";
            break;
    }
    return color;

}
//分页
var numb,firstpage,lastpage,nextpage,lastpage,txt,ptstate,color,key,cat;
var page=0;
var fengzi = $('#page a b').first();
var fengmu = $('#page a b').last();
var start = $('#start').val();
var end =$('#end').val();
query(1,"","");
num("","");
$('#change').blur(function(){
    query(1,"","");
    num("","");
});
//查询
$('#searchpt').click(function(){
   $('#participation').empty();
   key = $('#keysearch').val();
   cat = $('#category').val();
   query(1,key,cat);
   num(key,cat);
})
//首页
    function first(){
        query(1,key,cat);
        fengzi.text("1");
    }
//上一页    
    function previous(){
        
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi>1){
        zi= zi-1;
        fengzi.text(zi);
        query(zi,key,cat);
        }
    }
//下一页    
    function next(){
        var zi= parseInt(fengzi.text());
        var mu = parseInt(fengmu.text());
        if(zi<mu){
        zi= zi+1;
        fengzi.text(zi);
        query(zi,key,cat);
        }
    }
//尾页    
    function last(){
        query(fengmu.text(),key,cat);
        fengzi.text(fengmu.text());
    } 
//跳转
  function jump(){
   var jump = $('[name=jump]').val();
   var mu = parseInt(fengmu.text());
   if(1<=jump&&jump<=mu){
        fengzi.text(jump);
        query(jump,key,cat);
   }
  }    
//默认查询
function query(page,name,ptstate) {
    $('#participation').empty();
    txt = "";
    new Ajax("/my/product_search.jsp").keyvalue({"page": page,"name":name,"ptstate":ptstate}).getJson(function (json) {
        $.each(json, function (key, val) {
            switch (val['ptstate']) {
                case "1":
                    ptstate = "审核中";
                    color = "#4184e0"
                    break;
                case "2":
                    ptstate = "已通过";
                    color = "black"
                    break;
                case "3":
                    ptstate = "未通过";
                    color = "red";
                    break;
            }
            shijian = new Date(val["ptupdate"] * 1000).toString().substring(0,10);
            txt = txt + "<tr class='content1'><td>" + val["name"] + "</td><td><img src='/upfile/" + val["pt"] + "' style='height:100px; alt=''/></td><td style='color:" + color + "' class='statesy'>" + ptstate + "</td><td>" + shijian + "</td><td class='delete' value='" + val["id"] + "'>删除</td></tr>"
        })
      
        $('#participation').html(txt);
        $(window.parent).scrollTop(0);
        $('#participation tr td.delete').click(function(){
        $(window.parent.document).find('#sele').show();
        $(window.parent.document).find('#sele').attr("str","/my/product_delet.jsp");
        $(window.parent.document).find('#confirm').attr("val",$(this).attr("value"));
})
    })
}
//总页数
 function num(name,ptstate){
        new Ajax("/my/product_page.jsp").keyvalue({"name":name,"ptstate":ptstate}).get(function(data){
        numb = Math.ceil(data.replace(/[^0-9]/ig, "")/10);
        fengmu.text(numb);
    });
     fengzi.text("1");
    }
    

